import axios from 'axios'

export function request(config) {
    axios.defaults.withCredentials =true;

    const instance = axios.create({
       baseURL:'http://localhost:8080',
       timeout:5000
    })

    //请求拦截器
    instance.interceptors.request.use(config=>{
        //请求头添加 认证TOKEN
        if(localStorage.getItem('TOKEN')){
            config.headers.Authorization=`Bearer ${localStorage.getItem('TOKEN')}`
        }
        return config
    })

    //响应的拦截器
    instance.interceptors.response.use(res=>{
        return res.data
    },error=>{
        return Promise.reject(error.response.data)
    })

    return instance(config)

}